<?php
namespace app\channel\controller;
use think\Db;

class GameMaterial extends Base
{
    public function index(){
        if( request()->isAjax() ){
            $page = input('page');
            $limit = input('limit');
            $gameId = input('game_id');

            $where['status'] = 1;
            !empty($gameId) && $where['game_id'] = $gameId;

            if( ! $count=Db::name('GameMaterial')->where($where)->count() ){
                $this->layTable();
            }

            $select = Db::name('GameMaterial')
                ->where($where)
                ->order('add_time desc')
                ->limit(($page-1)*$limit, $limit)
                ->select();

            $data = [];

            $gameIdName = model('manage/Game')->gameIdName();
            foreach ($select as $k=>$v){
                $data[] = [
                    'id' => $v['id'],
                    'game_id' => $v['game_id'],
                    'game_name' => isset($gameIdName[ $v['game_id'] ]) ? $gameIdName[ $v['game_id'] ] : '游戏VIP等级表',
                    'url' => $v['url'],
                ];
            }
            $this->layTable(0, '游戏素材列表', $data, $count);
        }else{
            return view('');
        }
    }
}
